package com.edu.bhu.admin.controller.admin;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.LibBookType;
import com.edu.bhu.admin.service.ILibBookTypeService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 图书类型Controller
 * 
 * @author wwb
 * @date 2022-02-11
 */
@Controller
@RequestMapping("/admin/type")
public class LibBookTypeController extends BaseController
{
    private String prefix = "admin/type";

    @Autowired
    private ILibBookTypeService libBookTypeService;

    @RequiresPermissions("admin:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询图书类型列表
     */
    @RequiresPermissions("admin:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LibBookType libBookType)
    {
        startPage();
        List<LibBookType> list = libBookTypeService.selectLibBookTypeList(libBookType);
        return getDataTable(list);
    }

    /**
     * 查询图书类型列表（不分页）
     */
    @RequiresPermissions("admin:type:list")
    @PostMapping("/listNotPage")
    @ResponseBody
    public TableDataInfo listNotPage(LibBookType libBookType)
    {
        List<LibBookType> list = libBookTypeService.selectLibBookTypeList(libBookType);
        return getDataTable(list);
    }

    /**
     * 导出图书类型列表
     */
    @RequiresPermissions("admin:type:export")
    @Log(title = "图书类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LibBookType libBookType)
    {
        List<LibBookType> list = libBookTypeService.selectLibBookTypeList(libBookType);
        ExcelUtil<LibBookType> util = new ExcelUtil<LibBookType>(LibBookType.class);
        return util.exportExcel(list, "图书类型数据");
    }

    /**
     * 新增图书类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图书类型
     */
    @RequiresPermissions("admin:type:add")
    @Log(title = "图书类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LibBookType libBookType)
    {
        return toAjax(libBookTypeService.insertLibBookType(libBookType));
    }

    /**
     * 修改图书类型
     */
    @RequiresPermissions("admin:type:edit")
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") Long typeId, ModelMap mmap)
    {
        LibBookType libBookType = libBookTypeService.selectLibBookTypeByTypeId(typeId);
        mmap.put("libBookType", libBookType);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书类型
     */
    @RequiresPermissions("admin:type:edit")
    @Log(title = "图书类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LibBookType libBookType)
    {
        return toAjax(libBookTypeService.updateLibBookType(libBookType));
    }

    /**
     * 删除图书类型
     */
    @RequiresPermissions("admin:type:remove")
    @Log(title = "图书类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(libBookTypeService.deleteLibBookTypeByTypeIds(ids));
    }
}
